<template>
  <div class="container">
    <div v-if="isLoading" class="loading">
      <van-skeleton v-for="v in 10" :key="'key' + v" title :row="2" />
    </div>
    <van-pull-refresh v-model="refreshing" @refresh="onRefresh" v-else>
      <van-list
        v-model="loading"
        :finished="finished"
        finished-text="没有更多了"
        @load="onLoad"
      >
        <div class="item" v-for="m in list" >
          <div class="img">
            <img :src="m.verticalPic" alt="" />
          </div>
          <div class="title">
            <h1>{{ m.name }}</h1>
            <h2>{{ m.showTime }}</h2>
            <h3>{{ m.cityName }}|{{ m.venueName }}</h3>
            <div class="button">可选座</div>

            <div class="price">
              ￥<span>{{ m.priceLow }}</span
              >起
            </div>
          </div>
          <div class="score">{{ m.itemScore }}</div>
        </div>
      </van-list>
    </van-pull-refresh>
  </div>
</template>









<script>
import axios from "axios";
import Vue from "vue";
import { Skeleton, List, PullRefresh } from "vant";
Vue.use(Skeleton);
Vue.use(List);
Vue.use(PullRefresh);

export default {
  data() {
    return {
      list: [],

      isLoading: true,
      loading: false,
      finished: false,
      refreshing: false
    };
  },

  methods: {

     async loadData(){
      await fetch("./math/mathAll.json")
      .then(response => response.json())
      .then(result => {
        console.log(result.projectInfo)
       
      this.list = result.projectInfo;
      // this.isLoading = false;
        
      });
      console.log(this.list.length)
    },
      async onLoad() {
      // 在执行了下拉的动作后，this.refreshing, 即刻变为true
      if (this.refreshing) {
        this.list = []
       
        this.refreshing = false
      } 

      await this.loadData()
      
    },
     onRefresh() {
      // 清空列表数据
      this.finished = false

      // 重新加载数据
      // 将 loading 设置为 true，表示处于加载状态
      this.loading = true
      this.onLoad()
    }



  },
 async mounted() {
    //获取数据库里的数据

    // let result = axios.get(`./list.json`, {});
    // console.log(result);

    // fetch("./math/mathAll.json")
    //   .then(response => response.json())
    //   .then(result => {
    //     // console.log(result.projectInfo)
    //   this.list = result.projectInfo;
    //   this.isLoading = false;
        
    //   });
    await this.loadData()
    this.isLoading = false;
  }
};
</script>











<style lang='stylus' scoped>
@import '../../../assets/ellipsis.styl';

.container {
  .item {
    display: flex;
    padding: 0 0.3rem 0.27rem 0.21rem;

    .img {
      padding-right: 0.12rem;

      img {
        width: 1.01rem;
        height: 1.36rem;
      }
    }

    .title {
      flex: 1;

      h1 {
        font-size: 0.18rem;
        color: #000;
      }

      h2 {
        font-size: 0.12rem;
        font-weight: 100;
        color: #9c9ca4;
      }

      h3 {
        font-size: 0.14rem;
        font-weight: 100;
        color: #9c9ca4;
      }

      .button {
        width: 0.41rem;
        height: 0.12rem;
        font-size: 0.09rem;
        color: #6d7996;
      }

      .price {
        font-size: 0.12rem;
        margin-top: 0.3rem;
      }

      span {
        font-size: 0.16rem;
        color: #ea416b;
      }
    }
  }
}
</style>